package com.qxbb.report.controller;

import com.qxbb.report.bo.*;
import com.qxbb.report.service.ProductSalesService;
import com.qxbb.report.utils.StringUtils;
import com.qxbb.report.utils.http.HttpResult;
import com.qxbb.report.vo.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;

/**
 * @version 1.0
 * @author: pebble
 * @data 2023/10/9 13:20
 *  商品销售统计
 */
@RestController
@RequestMapping("sales")
@CrossOrigin
public class ProductSalesController {

    Logger logger = LoggerFactory.getLogger(LoginController.class);


    @Autowired
    private ProductSalesService productSalesService;

    /**
     * 查询某店铺，年份季度商品销售统计
     * @return
     */
    @PostMapping("/year")
    public HttpResult selectYear(@RequestBody ChainOrderSalerBO chainOrderSalerBO){
        logger.info(this.getClass() + ".selectYear 查询某店铺，年份季度商品销售统计:{}", chainOrderSalerBO);
        List<StatisticsYearVO> chainSalesOrderVO =  productSalesService.selectYear(chainOrderSalerBO);
        if (StringUtils.isNotNull(chainSalesOrderVO)){
            return HttpResult.ok(chainSalesOrderVO);
        }
        return HttpResult.ok("该时间段没有销售统计记录！");
    }


    /**
     * 查询某店铺，季度商品销售统计
     * @return
     */
    @PostMapping("/quanter")
    public HttpResult selectQuanter(@RequestBody QuanterChainSalerBO quanterChainSalerBO){
        logger.info(this.getClass() + ".selectQuanter 查询某店铺，季度商品销售统计:{}", quanterChainSalerBO);
        List<StatisticsQuanterVO> chainSalesOrderVO =  productSalesService.selectQuanter(quanterChainSalerBO);
        if (StringUtils.isNotNull(chainSalesOrderVO)){
            return HttpResult.ok(chainSalesOrderVO);
        }
        return HttpResult.ok("该时间段没有销售统计记录！");
    }

    /**
     * 查询某店铺，品牌销售统计
     * @return
     */
    @PostMapping("/brand")
    public HttpResult selectByBrand(@RequestBody BrandOrderSalerBO brandOrderSalerBO){
        logger.info(this.getClass() + ".selectByBrand 查询某店铺，品牌销售统计:{}", brandOrderSalerBO);
        List<BrandVO> chainSalesOrderVO =  productSalesService.selectByBrand(brandOrderSalerBO);
        if (StringUtils.isNotNull(chainSalesOrderVO)){
            return HttpResult.ok(chainSalesOrderVO);
        }
        return HttpResult.ok("该品牌没有销售统计记录！");
    }

    /**
     * 查询某店铺，类别销售统计
     * @return
     */
    @PostMapping("/category")
    public HttpResult selectByBrCategory(@RequestBody BrandOrderSalerBO brandOrderSalerBO){
        logger.info(this.getClass() + ".selectByBrCategory 查询某店铺，类别销售统计:{}", brandOrderSalerBO);
        List<CategoryVO> chainSalesOrderVO =  productSalesService.selectByCategory(brandOrderSalerBO);
        if (StringUtils.isNotNull(chainSalesOrderVO)){
            return HttpResult.ok(chainSalesOrderVO);
        }
        return HttpResult.ok("该类别没有销售统计记录！");
    }

    /**
     * 查询某店铺，品牌 --> 产品销售统计
     * @return
     */
    @PostMapping("/product")
    public HttpResult selectByProduct(@RequestBody ProductSalerBO productSalerBO) throws IOException {
        logger.info(this.getClass() + ".selectByProduct 查询某店铺，品牌 --> 产品销售统计:{}", productSalerBO);
        List<ProductStatisticsVO> chainSalesOrderVO =  productSalesService.selectByProduct(productSalerBO);
        if (StringUtils.isNotNull(chainSalesOrderVO)){
            return HttpResult.ok(chainSalesOrderVO);
        }
        return HttpResult.ok("该产品没有销售统计记录！");
    }



    /**
     * 查询某店铺，类别 --> 产品销售统计
     * @return
     */
    @PostMapping("/categoryDetails")
    public HttpResult selectCategoryDetail(@RequestBody CatetoryDetailBO catetoryDetailBO) throws IOException {
        logger.info(this.getClass() + ".selectCategoryDetail 查询某店铺，类别 --> 产品销售统计:{}", catetoryDetailBO);
        List<ProductStatisticsVO> chainSalesOrderVO =  productSalesService.selectCategoryDetail(catetoryDetailBO);
        if (StringUtils.isNotNull(chainSalesOrderVO)){
            return HttpResult.ok(chainSalesOrderVO);
        }
        return HttpResult.ok("该产品没有销售统计记录！");
    }

    /**
     * 货品库存追踪
     * @return
     */
    @PostMapping("/details")
    public HttpResult  selectGoodsDetails(@RequestBody GoodsDetailsBO goodsDetailsBO){
        logger.info(this.getClass() + ".selectGoodsDetails 查询货品库存追踪：{}",goodsDetailsBO);
        List<GoodsDetailsVO> list =  productSalesService.selectGoogSDetails(goodsDetailsBO);
        if (StringUtils.isNotNull(list)){
            return HttpResult.ok(list);
        }
        return HttpResult.ok("无货品追踪记录信息！");

    }


}
